﻿

using Blog.Core.EFcore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
using Microsoft.Extensions.Configuration;
using System.Data.SqlTypes;

namespace Blog.Core.Api
{
    public static class ServiceExtensions
    {
        public static void AddDbConextSetup(this IServiceCollection services, IConfiguration configuration)
        {
            //注册数据库的服务
            if(configuration["SqlType"] == "SqlServer")
            {
                string sqlserverconnectionString = configuration.GetConnectionString("SqlServerContext");
                services.AddDbContext<DbContext,SqlServerContext>(options => options.UseSqlServer(sqlserverconnectionString));
            }
            if(configuration["SqlType"] == "MySql")
            {
                string mysqlconnectionString = configuration.GetConnectionString("MySqlContext");
                services.AddDbContext<DbContext,MySqlContext>(options => options.UseMySql(mysqlconnectionString,ServerVersion.AutoDetect(mysqlconnectionString)));
            }            
            //services.AddDbContext<MySqlContext>(options => options.UseMySql(connectionString2));

        }
    }
}
